package com.suishoupai.xmb.utils;

import com.github.pagehelper.PageHelper;
import org.apache.commons.collections4.MapUtils;
import org.springframework.security.access.method.P;

import java.util.Map;

/**
 * Created by caojian on 2017/3/29.
 */
public class PageUtil {
    /**
     * 分页
     *
     * @param map
     */
    public static void startPage(Map map) {
        PageUtil.startPage(map, true);
    }

    /**
     * 分页
     *
     * @param map
     */
    public static void startPage(Map map, boolean count) {
        int pageNum = MapUtils.getIntValue(map, "pageNum", 1);
        if (pageNum < 1) {
            pageNum = 1;
        }
        int pageSize = MapUtils.getIntValue(map, "pageSize", 10);
        if (pageSize < 10) {
            pageSize = 10;
        }
        PageHelper.startPage(pageNum, pageSize, count);
    }

    public static void startPage(int pageNum, int pageSize, boolean count) {
        if (pageNum < 1) {
            pageNum = 1;
        }
        if (pageSize < 10) {
            pageSize = 10;
        }
        PageHelper.startPage(pageNum, pageSize, count);
    }
}
